#!/usr/bin/env bash

set -e

echo " ┌──────────────────────────────────────────────┐"
echo " │    Compiling Workflow contracts...           │"
echo " └──────────────────────────────────────────────┘"

PROJECT="workflow"

CONTRACTS_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; cd ../ && pwd -P )"
export FOUNDRY_PROFILE="$PROJECT"

compileContract () {
  local profile="$1"
  local src_rel="$2"
  local contract=$(basename "$src_rel")
  echo "Compiling" "$contract"

  env FOUNDRY_PROFILE="$profile" forge build \
  "$CONTRACTS_DIR/src/v0.8/$PROJECT/$src_rel.sol" \
  --root "$CONTRACTS_DIR" \
  --extra-output-files bin abi \
  -o "$CONTRACTS_DIR/solc/$PROJECT/$src_rel"
}

compileContract workflow-v1 v1/WorkflowRegistry
compileContract workflow-v2 dev/v2/WorkflowRegistry
compileContract workflow-v2 dev/v2/CapabilitiesRegistry
